@echo off
:: Script to download and install Anaconda on Windows 11

:: Automatically request administrator privileges
:: Check if running as administrator
net session >nul 2>&1
if %errorLevel% == 0 (
    echo Running as administrator...
) else (
    echo Requesting administrator privileges...
    :: Re-launch the script with administrator privileges
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

:: Set the download URL for Anaconda
set ANACONDA_URL=https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Windows-x86_64.exe

:: Set the path to save the installer (default Downloads folder)
set DOWNLOAD_PATH=%USERPROFILE%\Downloads\Anaconda3-2023.09-0-Windows-x86_64.exe

:: Check if Anaconda is already installed
if exist "C:\anaconda3" (
    echo Anaconda is already installed at C:\anaconda3.
    goto INSTALL
)

:: Check if the installer already exists in the Downloads folder
if exist "%DOWNLOAD_PATH%" (
    echo Anaconda installer already exists at %DOWNLOAD_PATH%.
    goto INSTALL
)

:: Download the Anaconda installer using PowerShell
echo Downloading Anaconda installer...
powershell -Command "Invoke-WebRequest -Uri '%ANACONDA_URL%' -OutFile '%DOWNLOAD_PATH%'"

:: Check if the download was successful
if not exist "%DOWNLOAD_PATH%" (
    echo Failed to download Anaconda installer!
    pause
    exit /b
)

:INSTALL
:: Install Anaconda with GUI (non-silent)
echo Starting Anaconda installation...
start "" "%DOWNLOAD_PATH%"

:: Wait for the user to complete the installation
echo Please complete the Anaconda installation using the GUI.
pause

:: Check if the installation was successful
if not exist "C:\anaconda3" (
    echo Anaconda installation failed or was not completed!
    pause
    exit /b
)

:: Add Anaconda to the system environment variables
echo Adding Anaconda to system environment variables...
set ANACONDA_PATH=C:\anaconda3
set ANACONDA_SCRIPTS_PATH=%ANACONDA_PATH%\Scripts
set ANACONDA_LIBRARY_PATH=%ANACONDA_PATH%\Library\bin
setx PATH "%PATH%;%ANACONDA_PATH%;%ANACONDA_SCRIPTS_PATH%;%ANACONDA_LIBRARY_PATH%" /M

:: Clean up the installer (optional)
echo Cleaning up the installer...
del "%DOWNLOAD_PATH%"

echo Anaconda installation and configuration completed!
pause